#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#pragma unmanaged 
#include <ql\termstructures\volatility\abcdcalibration.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL::Math::Optimization;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Termstructures { namespace Volatility {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IAbcdCalibration
	public ref class CAbcdCalibration : 
            public System::MarshalByRefObject,
            public Cephei::QL::Termstructures::Volatility::IAbcdCalibration
	{
	protected: 
		boost::shared_ptr<QuantLib::AbcdCalibration>* _ppAbcdCalibration;
        boost::detail::spinlock* _pSpinlock;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::AbcdCalibration>* _phAbcdCalibration;
#endif
		Object^ _AbcdCalibrationOwner;     // reference to object that manages the storage for this object
	internal:
		CAbcdCalibration (Cephei::IVector<Double>^ t, Cephei::IVector<Double>^ blackVols, Microsoft::FSharp::Core::FSharpOption<Double>^ aGuess, Microsoft::FSharp::Core::FSharpOption<Double>^ bGuess, Microsoft::FSharp::Core::FSharpOption<Double>^ cGuess, Microsoft::FSharp::Core::FSharpOption<Double>^ dGuess, Microsoft::FSharp::Core::FSharpOption<Boolean>^ aIsFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ bIsFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ cIsFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ dIsFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ vegaWeighted, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>^ endCriteria, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>^ method);
		CAbcdCalibration ();
        CAbcdCalibration (boost::shared_ptr<QuantLib::AbcdCalibration>& childNative, Object^ owner);
        CAbcdCalibration (QuantLib::AbcdCalibration& childNative, Object^ owner);
        CAbcdCalibration (CAbcdCalibration^ copy);
        CAbcdCalibration (System::Type^ t);
#ifdef STRUCT
        CAbcdCalibration (QuantLib::AbcdCalibration childNative);
#endif       
#ifdef HANDLE
		CAbcdCalibration (QuantLib::Handle<QuantLib::AbcdCalibration>& childNative, Object^ owner);
		CAbcdCalibration (QuantLib::Handle<QuantLib::AbcdCalibration> childNative);
#endif
		virtual ~CAbcdCalibration ();
		!CAbcdCalibration ();

	internal:
		QuantLib::AbcdCalibration& GetReference ();
		boost::shared_ptr<QuantLib::AbcdCalibration>& GetShared ();
		QuantLib::AbcdCalibration* GetPointer ();
        void SetAbcdCalibration (boost::shared_ptr<QuantLib::AbcdCalibration> native)
        {
            if (_ppAbcdCalibration != NULL)
                delete _ppAbcdCalibration;
            _ppAbcdCalibration = new boost::shared_ptr<QuantLib::AbcdCalibration> (native);
            
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::AbcdCalibration>& GetHandle ();
#endif
		virtual bool HasNative () ;
		void Lock ()
		{
			if (Cephei::QL::Settings::_ReferenceLocking)
    			_pSpinlock->lock ();
		}
		void Unlock ()
		{
			_pSpinlock->unlock ();
		}
    public:
        property Double A 
        {
		    virtual Double get () ;
        }
        property Double B 
        {
		    virtual Double get () ;
        }
        property Double C 
        {
		    virtual Double get () ;
        }
        property Cephei::QL::Termstructures::Volatility::IAbcdCalibration^ Compute 
        {
		    virtual Cephei::QL::Termstructures::Volatility::IAbcdCalibration^ get () ;
        }
        property Double D 
        {
		    virtual Double get () ;
        }
        property QL::Math::Optimization::EndCriteria::TypeEnum EndCriteria 
        {
		    virtual QL::Math::Optimization::EndCriteria::TypeEnum get () ;
        }
        property Double Error 
        {
		    virtual Double get () ;
        }
		virtual Cephei::IVector<Double>^ K (Cephei::IVector<Double>^ t, Cephei::IVector<Double>^ blackVols) ;
        property Double MaxError 
        {
		    virtual Double get () ;
        }
		virtual Double Value (Double x) ;
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CAbcdCalibration_Factory : public System::MarshalByRefObject,  public IAbcdCalibration_Factory
	{
	public:
        virtual IAbcdCalibration^ Create (Cephei::IVector<Double>^ t, Cephei::IVector<Double>^ blackVols, Microsoft::FSharp::Core::FSharpOption<Double>^ aGuess, Microsoft::FSharp::Core::FSharpOption<Double>^ bGuess, Microsoft::FSharp::Core::FSharpOption<Double>^ cGuess, Microsoft::FSharp::Core::FSharpOption<Double>^ dGuess, Microsoft::FSharp::Core::FSharpOption<Boolean>^ aIsFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ bIsFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ cIsFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ dIsFixed, Microsoft::FSharp::Core::FSharpOption<Boolean>^ vegaWeighted, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IEndCriteria^>^ endCriteria, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Math::Optimization::IOptimizationMethod^>^ method);
        virtual IAbcdCalibration^ Create ();
    };
   
/*Cephei*/ } /*QL*/ } /*Termstructures*/ } /*Volatility */}
